package ua.kpi_java_training.zabrodskyi.module3;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * @author Maksym Zabrodskyi
 * @version 22-Jun-2013
 */
public class BarrierTest {

	Barrier barrier;
	Cell cell;

	@Test
	public void shouldCreateBarrier() {
		cell = new Cell(1,1);
		barrier = new Barrier(cell);
		assertNotNull(barrier);
	}
	
	@Test(expected = Exception.class)
	public void shouldNotCreateBarrierBecauseNegativeCoordinats() {
		cell = new Cell(-1,-1);
		barrier = new Barrier(cell);
	}
	
	@Test(expected = Exception.class)
	public void shouldNotCreateBarrierBecauseBadCoordinats() {
		cell = new Cell(15, 15);
		barrier = new Barrier(cell);
	}

	@Test
	public void shouldGetCellInWitchBarrierIsIt() {
		cell = new Cell(4, 5);
		barrier = new Barrier(cell);
		Cell newCell = barrier.getCell();
		assertTrue(cell.equals(newCell));
	}

	@Test
	public void shouldSetNewCellForBarrier() {
		cell = new Cell(4, 5);
		barrier = new Barrier(cell);
		Cell newCell = new Cell(1, 2);
		barrier.setCell(newCell);
		cell = barrier.getCell();
		assertTrue(cell.equals(newCell));
	}
	
	@Test(expected = Exception.class)
	public void shouldExceptionSetNewCellForBarrier() {
		cell = new Cell(4, 5);
		barrier = new Barrier(cell);
		Cell newCell = new Cell(-1, -2);
		barrier.setCell(newCell);
	}

	@Test
	public void shouldGetTypeBarrier() {
		cell = new Cell(4, 5);
		barrier = new Barrier(cell);
		ElementType type = barrier.getType();
		assertEquals(ElementType.BARRIER, type);
	}
	
	@Test
	public void testToString() {
		cell = new Cell(4, 5);
		barrier = new Barrier(cell);
		String expected = "BARRIER is on cell [4,5]";
		assertEquals(expected, barrier.toString());
	}

}
